#pragma once

//#include "../../include/imilog.h"
#include "imierrorcode.h"
#include "imicodecffmpegapi.h"
#include <string.h>
#include <stdio.h>
#include <list>
#include "imiapihandlemap.h"
#include "com_chuangmi_decoder_ImiVideoDecoder.h"

//ffmpeg
#ifdef __cplusplus
extern "C"{
#endif
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libavformat/avio.h"
#include "libavutil/mem.h"
#include "libswscale/swscale.h"
#include "libswresample/swresample.h"
#ifdef __cplusplus
}
#endif

#ifndef WIN32
//#include "../../include/imiwin2linux.h"
#endif

using namespace std;

namespace imimediacore_namespace
{
	class imicodecffmpegapi_impl
	{
	public:
		imicodecffmpegapi_impl();
		~imicodecffmpegapi_impl();
	public:
		int init();
		int fini();
		int setdecoder(int type);
		int decode(unsigned char* data, int len);
		int width();
		int height();
		int totexture(int y, int u, int v);
		int yuvdata(unsigned char* y, unsigned char* u, unsigned char* v);
		int jpegdata(unsigned char* y, unsigned char* u, unsigned char* v, unsigned char* buffer, int w, int h, int q);
	private:
		unsigned int _type;
		unsigned int _width;
		unsigned int _height;
	private:
		int _inith265lib();
		void _finih265lib();
		AVCodecContext* _h265_avcodec;
		AVFrame* _h265_avframe;
	private:
		int _inith264lib();
		void _finih264lib();
		AVCodecContext* _h264_avcodec;
		AVFrame* _h264_avframe;
	private:
		void _copyFrameData(unsigned char* data, int linesize, int width, int height, unsigned char* out);
	};
}
